package cn.italkcloud.cph.helper;

import cn.italkcloud.cph.entity.VosCustomer;
import cn.italkcloud.cph.entity.VosServer;
import cn.italkcloud.cph.entity.dto.vos.*;
import cn.italkcloud.cph.entity.wrapper.VosWrapper;
import cn.italkcloud.cph.utils.DateUtil;
import org.junit.Test;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author dominate
 * @since 2024/7/8
 **/
public class VosHelperDebug {

    private final VosServer vosServer = new VosServer()
            .setApiUrl("http://192.168.209.1:9090/")
            .setMysqlUrl("jdbc:mysql://127.0.0.1:3307/vos3000")
            .setMysqlUser("vos_report")
            .setMysqlPassword("vos_report@123456");

    @Test
    public void test() {
        int count = DateUtil.daysOfTwoDate(new Date(), DateUtil.strToFormatDate("2024-09-12", DateUtil.DATA_FORMAT_SIXTH));
        System.out.println(count);
        count = DateUtil.daysOfTwoDate(new Date(), DateUtil.strToFormatDate("2024-09-11", DateUtil.DATA_FORMAT_SIXTH));
        System.out.println(count);
        count = DateUtil.daysOfTwoDate(new Date(), DateUtil.strToFormatDate("2024-09-13", DateUtil.DATA_FORMAT_SIXTH));
        System.out.println(count);
    }

    @Test
    public void debugRequestCustomer() {
        List<String> customerNameList = VosHelper.getAllCustomerNameList(vosServer.getApiUrl());
        for (String customerName : customerNameList) {
            System.out.println(customerName);
        }
    }

    @Test
    public void debugRequestCustomerDetail() {
        CustomerDetailDTO customerDetail = VosHelper.getCustomerDetail(vosServer.getApiUrl(), "测试账户");
        System.out.println(customerDetail);
        VosCustomer vosCustomer = VosWrapper.builder().entityDTO(customerDetail);
        System.out.println(vosCustomer);
    }

    @Test
    public void debugRequestPayHistory() {
        //PayHistoryDTO(account=测试账户, fee=150306.000, type=0, payType=0, customerMoney=-143197.900, payTime=1740141124895, memo=1月费用结算)
        List<PayHistoryDTO> payHistoryList = VosHelper.getPayHistory(vosServer.getApiUrl(), "测试账户", DateUtil.strToDate("2025-02-01"), DateUtil.strToDate("2025-02-26"));
        System.out.println(payHistoryList.size());
        for (PayHistoryDTO payHistory : payHistoryList) {
            System.out.println(payHistory);
        }
    }

    @Test
    public void debugPay() {
        PayDTO pay = VosHelper.payCustomer(vosServer.getApiUrl(), "测试账户", new BigDecimal("500"), "API-充值测试");
        System.out.println(pay);
    }

    @Test
    public void debugReport() {
        ReportCustomerFeeDTO fee = VosHelper.getMonthCustomerReport(vosServer.getApiUrl(), DateUtil.strToDate("2024-07-01"), "测试账户");
        System.out.println(fee);
    }

    @Test
    public void debugGetawayReport() {
        Date startDate = DateUtil.strToFormatDate("20250201", DateUtil.DATA_FORMAT_DAY);
        Date endDate = DateUtil.strToFormatDate("20250203", DateUtil.DATA_FORMAT_DAY);
        List<ReportGatewayFeeDTO> reportList = VosHelper.getGatewayReport(vosServer, startDate, endDate, "测试账户");
        for (ReportGatewayFeeDTO reportGatewayFee : reportList) {
            System.out.println(reportGatewayFee);
        }
    }

    @Test
    public void debugServerCheck() {
        boolean isConnection = VosHelper.checkServerMysqlConnection(vosServer.getMysqlUrl(), vosServer.getMysqlUser(), vosServer.getMysqlPassword());
        System.out.println("MySQL connection " + isConnection);
        isConnection = VosHelper.checkServerApiConnection(vosServer.getApiUrl());
        System.out.println("API connection " + isConnection);
    }

}
